﻿using BLWCMS.Core.IBusiness;
using BLWCMS.Core.Models;
using Nancy.ModelBinding;

namespace BLWCMS.Web.Modules
{
    public class BindingModule:BaseModule
    {
        private readonly IWeixinConfigBusiness _weixinConfigBusiness;

        public BindingModule(IWeixinConfigBusiness weixinConfigBusiness)
            : base("/binding", true)
        {
            _weixinConfigBusiness = weixinConfigBusiness;

            Get["/"] = p => GetIndex();

            Post["/"] = p => PostIndex();
        }

        private dynamic GetIndex()
        {
            ViewBag.SysUrl = Request.Url.SiteBase;
            ViewBag.SysPort = Request.Url.Port;
            WeixinConfigModel weixinConfigModel = _weixinConfigBusiness.GetModel();
            return View["Index", weixinConfigModel];
        }

        private dynamic PostIndex()
        {
            WeixinConfigModel weixinConfigModel = this.Bind<WeixinConfigModel>();
            return _weixinConfigBusiness.WriteWeixinConfig(weixinConfigModel);
        }
    }
}